package com.objectproject.main.service;

import java.util.ArrayList;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.objectproject.main.dao.MyGroupDAOImpl;
import com.objectproject.main.dao.MyGroupHierarchyDAOImpl;
import com.objectproject.main.model.MyGroup;
import com.objectproject.main.service.iface.MyGroupService;
import com.objectproject.main.service.subsystem.MyLocaleResolver;

@Service
public class MyGroupServiceImpl implements MyGroupService {

	@Autowired
	MyGroupDAOImpl myGroupDAOImpl;
	
	@Autowired
	MyGroupHierarchyDAOImpl myGroupHierarchyDAOImpl;
	
	@Autowired
	MyLocaleResolver myLocaleResolver;
	
	@Autowired
	MyGroupHierarchyServiceImpl myGroupHierarchyServiceImpl;
	
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public long createMyGroup(MyGroup myGroup, Locale locale) {
		
		// 1. 그룹 삽입
		myGroupDAOImpl.insertMyGroup(myGroup);
		

		// 2. 그룹 디테일 삽입
		//먼저 디테일 잇는지 확인--------------------------------------------------
		myGroupDAOImpl.insertMyGroupDetail(myGroup, myLocaleResolver.resolveLocaleId(locale));
		
		return myGroup.getGroupId();
	}

	@Override
	public void removeMyGroup(long groupId) {
		
		//신분확인
		
		myGroupDAOImpl.deleteMyGroupById(groupId);
	}

	@Override
	public void reviseMyGroup(MyGroup myGroup) {
		myGroupDAOImpl.updateMyGroup(myGroup);
	}

	@Override
	public MyGroup getMyGroup(long groupId) {
		return myGroupDAOImpl.selectMyGroupById(groupId);
	}

}
